#include "stm32f10x.h"                  // Device header
#include "OLED.h"
#include "Delay.h"
#include "led.h"
#include "Serial.h"
#include <string.h>


int main(void)
{
	Led_Init();
	OLED_Init();
	Serial_Init();
	
	Serial_SendString("Start\r\n");
	
	OLED_ShowString(1, 1, "Send:");
	OLED_ShowString(3, 1, "Receive:");
	
	while(1) {
		if (Serial_RxFlag == 1) {
			OLED_ShowString(4, 1, "                ");
			OLED_ShowString(4, 1, Serial_RxPacket);
			if (strcmp(Serial_RxPacket, "on") == 0) {
				Led_On();
				OLED_ShowString(2, 1, "                "); 
				OLED_ShowString(2, 1, ">OK");
				Serial_SendString("OK\r\n");
			} else if (strcmp(Serial_RxPacket, "off") == 0) {
				Led_Off();
				OLED_ShowString(2, 1, "                ");
				OLED_ShowString(2, 1, "OK");
				Serial_SendString("OK\r\n");
			} else if (strcmp(Serial_RxPacket, "turn") == 0) {
				Led_Turn();
				OLED_ShowString(2, 1, "                ");
				OLED_ShowString(2, 1, "OK");
				Serial_SendString("OK\r\n");
			} else {
				OLED_ShowString(2, 1, "                ");
				OLED_ShowString(2, 1, "UNKNOW");
				Serial_SendString("UNKNOW\r\n");
			}
			Serial_RxFlag = 0;
		}
	}
}
